package com.commerce.constellation;

import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetSequence;
import com.getkeepsafe.taptargetview.TapTargetView;

public class TopActivity extends AppCompatActivity implements View.OnClickListener {

    private Button topToday;
    private Button topTomorrow;
    private Button topWeek;
    private Button topMonth;
    private Button topYear;
    private Button topXzpd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_top);
        initViews();
        SharedPreferences sign = getSharedPreferences("sign", MODE_PRIVATE);
        if(sign.getBoolean("show", true))
        showTap();
        sign.edit().putBoolean("show",false).apply();
    }
    //用户引导
    private void showTap() {
        new TapTargetSequence(this).targets(
                TapTarget.forView(topToday,"今天运势查询","今天日期、综合指数、健康指数、爱情指数、财运指数、工作指数、速配星座、幸运数字和今日概述。")
                        .drawShadow(true).tintTarget(false).targetRadius(200).targetCircleColor(R.color.colorPrimary).cancelable(false),
                TapTarget.forView(topTomorrow,"明天运势查询","明天日期、综合指数、健康指数、爱情指数、财运指数、工作指数、速配星座、幸运数字和今日概述。")
                        .drawShadow(true).tintTarget(false).targetRadius(200).targetCircleColor(R.color.colorPrimary).cancelable(false),
                TapTarget.forView(topWeek,"本周运势查询","本周日期、爱情运势描述、学业运势描述、事业运势描述、财富运势描述。")
                        .drawShadow(true).tintTarget(false).targetRadius(200).targetCircleColor(R.color.colorPrimary).cancelable(false),
                TapTarget.forView(topMonth,"本月运势查询","本月日期、综合运势、工作运势、健康运势、财运运势。")
                        .drawShadow(true).tintTarget(false).targetRadius(200).targetCircleColor(R.color.colorPrimary).cancelable(false),
                TapTarget.forView(topYear,"今年运势查询","总体描述、具体描述、幸运色、事业运、感情运、财运。")
                        .drawShadow(true).tintTarget(false).targetRadius(200).targetCircleColor(R.color.colorPrimary).cancelable(false),
                TapTarget.forView(topXzpd,"星座配对查询","配对比重、总体描述、配对指数、两情相悦指数、天长地久指数、恋爱建议、注意事项。")
                        .drawShadow(true).tintTarget(false).targetRadius(200).targetCircleColor(R.color.colorPrimary).cancelable(false)).start();
    }

    private void initViews() {
        topToday = findViewById(R.id.top_today);
        topTomorrow = findViewById(R.id.top_tomorrow);
        topWeek = findViewById(R.id.top_week);
        topMonth = findViewById(R.id.top_month);
        topYear = findViewById(R.id.top_year);
        topXzpd = findViewById(R.id.top_xzpd);
        TextView userName = findViewById(R.id.userName);
        userName.setText("欢迎用户："+getIntent().getStringExtra("userName"));
        topToday.setOnClickListener(this);
        topTomorrow.setOnClickListener(this);
        topWeek.setOnClickListener(this);
        topMonth.setOnClickListener(this);
        topYear.setOnClickListener(this);
        topXzpd.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(TopActivity.this,MainActivity.class);
        switch (v.getId()){
            case R.id.top_today :
                  intent.putExtra("type","today");
                break;
            case R.id.top_tomorrow :
                 intent.putExtra("type","tomorrow");
                break;
            case R.id.top_week :
                 intent.putExtra("type","week");
                break;
            case R.id.top_month :
                intent.putExtra("type","month");
                break;
            case R.id.top_year :
                intent.putExtra( "type","year");
                break;
            case R.id.top_xzpd :
                intent = new Intent(TopActivity.this,XzpdActivity.class);
                break;
        }
        startActivity(intent);
    }
    /**
     * 第一次返回退出应用提示
     */
    protected long exitTime; //记录第一次点击时的时间
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK
                && event.getAction() == KeyEvent.ACTION_DOWN) {
            if ((System.currentTimeMillis() - exitTime) > 2000) {
                Toast.makeText(TopActivity.this, "再按一次退出星座",
                        Toast.LENGTH_SHORT).show();
                exitTime = System.currentTimeMillis();
            } else {
                finish();
                System.exit(0);
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}